﻿CREATE FUNCTION [dbo].[fn_TriggerExists]
(
	@Table    sysname,
	@Trigger  sysname
)
RETURNS BIT
AS
BEGIN
	DECLARE @True  BIT; SET @True  = 1
	DECLARE @False BIT; SET @False = 0
	DECLARE @Object sysname; SET @Object = PARSENAME(@Table, 1)
	DECLARE @Schema sysname; SET @Schema = ISNULL(PARSENAME(@Table, 2), 'dbo')	
	
	IF EXISTS (
	       SELECT *
	       FROM   sys.tables t
	              INNER JOIN sys.objects o
	                   ON  t.[object_id] = o.[object_id]
	              INNER JOIN sys.triggers tr
	                   ON  o.[object_id] = tr.parent_id
	       WHERE  t.[name] = @Object
                  AND t.[type] = 'U'
	              AND tr.[name] = @Trigger
				  AND schema_name(t.schema_id) = @Schema
	   )
	    RETURN @True
	
	RETURN @False
END